package com.example.qxfw.qxzs.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.entity.qx.SpecialSrvStation;
import com.example.qxfw.common.entity.zy.Zhishu;
import com.example.qxfw.qxzs.service.SpecialSrvStationService;
import com.example.qxfw.qxzs.service.ZhishuService;
import com.example.qxfw.ybzz.service.SysConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "指数预报-预报指数查询接口")
@RestController
@CrossOrigin
@RequestMapping("/zsybcx")
public class ZsybcxController {

    @Autowired
    private ZhishuService zhishuService;

    @Autowired
    private SpecialSrvStationService specialSrvStationService;

    @Autowired
    private SysConfigService sysConfigService;

    @ApiOperation("获取指数最新时间")
    @GetMapping("/getMaxTime")
    public SysResult getMaxTime() {
        List<Zhishu> maxTime = zhishuService.getMaxTime();
        return SysResult.success(maxTime.get(0).getDatechar());
    }

    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "cityId", value = "站点编号", dataType = "String", required = true),
            @ApiImplicitParam(name = "dateChar1", value = "yyyy-MM-dd 00:00:00", dataType = "String", required = true),
            @ApiImplicitParam(name = "timeChar1", value = "上午-08 下午-20", dataType = "String", required = true),
            @ApiImplicitParam(name = "dateChar2", value = "yyyy-MM-dd 00:00:00", dataType = "String", required = true),
            @ApiImplicitParam(name = "timeChar2", value = "上午-08 下午-20", dataType = "String", required = true)
    })
    @ApiOperation("查询指数")
    @GetMapping("/getZhishuByParam")
    public SysResult getZhishuByParam(String cityId, String dateChar1, String timeChar1, String dateChar2, String timeChar2) {
        List<Zhishu> zhishus = zhishuService.listByParam(cityId, dateChar1, timeChar1, dateChar2, timeChar2);
        if(zhishus.size()>0){
            return SysResult.success(zhishus);
        }
        return SysResult.fail("未查询到指数");
    }

    @ApiOperation("查询所有指数")
    @GetMapping("/getZhishuAll")
    public SysResult getZhishuAll() {
        List<Zhishu> list2 = zhishuService.getList2();
        return SysResult.success(list2);
    }

    @ApiOperation("查询站点类型")
    @GetMapping("/getStationFlag")
    public SysResult getStationFlag() {
        List<String> list = specialSrvStationService.getStationFlag();
        return SysResult.success(list);
    }

    @ApiOperation("根据站点类型查询站点信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "flag", value = "文件类型：全部/墒情站/地面站/指数站/高空站", dataType = "String", required = true)
    })
    @GetMapping("/getStationByFlag")
    public SysResult getStationByFlag(String flag) {
        if (flag.equals("全部")) {
            List<SpecialSrvStation> list = specialSrvStationService.getList();
            return SysResult.success(list);
        }
        List<SpecialSrvStation> specialSrvStations = specialSrvStationService.getList2(flag);
        return SysResult.success(specialSrvStations);
    }


}
